import { defineStore } from 'pinia'
import {ref} from 'vue'

export const useTokenStore = defineStore(
    'userToken',
    () => {
        const token = ref('')
        const clearToken = () => {
            token.value = ''
        }
        const setToken = (t) => {
            console.log(11)
            token.value = t
        }
        return {token, clearToken, setToken}
    },
    {
        // 需要先在 main.js 注入持久化插件
        persist: {
            storage: localStorage,   // ✅ 注意拼写
            paths: ['token']         // 只持久化 token 字段
        }
    }
)